using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace TemplateWeb.Controllers
{
	#region using
	using System.Web.Mvc;
	using TemplateWeb.Models.ViewModels;
	using TemplateWeb.Models;
	using TemplateWeb.Models.Repositories;
	using TemplateWeb.Helpers;
	using System.Web.Security;
	#endregion
	public partial class AdminController: BaseController
	{
		public ActionResult SelectLoaiBatDongSan()
		{
			var data = new DataTransferViewModel
			{
				EnumViewModelType = EnumViewModel.ADMIN_LOAIBATDONGSAN
			};
			return View(CreateViewModel(data));
		}

		public ActionResult SelectLoaiBatDongSanPaging(int page = 1)
		{
			var data = new DataTransferViewModel
			{
				EnumViewModelType = EnumViewModel.ADMIN_LOAIBATDONGSAN,
				CurrentPage = page
			};
			return PartialView("Templates/TH_ListLoaiBatDongSan", CreateViewModel(data));
		}


		[AcceptVerbs(HttpVerbs.Delete)]
		public JsonResult DeleteLoaiBatDongSan(int id)
		{
			return Json(new{
				Success = _repLoaiBatDongSan.Delete(id),
				RecordCount = _repLoaiBatDongSan.SelectAll().Count,
				DeleteId = id
			});
		}

		public ActionResult EditLoaiBatDongSan(int page, int id)
		{
			var data = new DataTransferViewModel
			{
				EnumViewModelType = EnumViewModel.ADMIN_LOAIBATDONGSAN,
				CurrentPage = page,
				EditID = id
			};
			return PartialView("Templates/TH_EditLoaiBatDongSan", CreateViewModel(data));
		}

		public ActionResult CancelEditingLoaiBatDongSan(int page)
		{
			var data = new DataTransferViewModel
			{
				EnumViewModelType = EnumViewModel.ADMIN_LOAIBATDONGSAN,
				CurrentPage = page
			};
			return PartialView("Templates/TH_ListLoaiBatDongSan", CreateViewModel(data));
		}

		[ValidateInput(false)]
		[AcceptVerbs(HttpVerbs.Post)]
		public ActionResult UpdateLoaiBatDongSan(FormCollection forms)
		{
			string id = forms.GetValues("LoaiBatDongSan_ID")[0];
			string tenloaibatdongsan = forms.GetValues("LoaiBatDongSan_TenLoaiBatDongSan")[0];
			string currentpage = forms.GetValues("LoaiBatDongSan_CurrentPage")[0];
			var loaibatdongsan = _repLoaiBatDongSan.SelectByID(int.Parse(id));
			loaibatdongsan.TenLoaiBatDongSan = tenloaibatdongsan;
			var result = _repLoaiBatDongSan.Save();
			var data = new DataTransferViewModel
			{
				EnumViewModelType = EnumViewModel.ADMIN_LOAIBATDONGSAN,
				CurrentPage = int.Parse(currentpage)
			};
            return View("SelectLoaiBatDongSan", CreateViewModel(data));
		}


		[ValidateInput(false)]
		[AcceptVerbs(HttpVerbs.Post)]
		public ActionResult InsertLoaiBatDongSan(FormCollection forms)
		{
			string tenloaibatdongsan = forms.GetValues("LoaiBatDongSan_TenLoaiBatDongSan")[0];
			var newItem = new LoaiBatDongSan
			{
				TenLoaiBatDongSan = tenloaibatdongsan
			};
			var result = _repLoaiBatDongSan.Insert(newItem);
			var data = new DataTransferViewModel
			{
				EnumViewModelType = EnumViewModel.ADMIN_LOAIBATDONGSAN,
				Added = result
			};
            return View("SelectLoaiBatDongSan", CreateViewModel(data));
		}


	}
}